fn main() {
  //1. 定义结构体
  struct User {
    name: String,
    id: String,
    nonce: u64,
    active: bool
  }

  //2. 创建结构体示例
  let ahhh = User {
    name: String::from("ahhh"),
    id: String::from("91209012"),
    nonce: 10000,
    active: true
  };

  //3. 修改结构体字段
  let mut ahhh2 = User {
    name: String::from("ahhh"),
    id: String::from("91209012"),
    nonce: 10000,
    active: true
  };
  ahhh2.nonce = 20000;

  //4. 参数名字和字段名同名的简写方法
  let name = String::from("ahhh");
  let id = String::from("89wf8uf");
  let nonce = 2000000;
  let active = false;
  let user1 = User {
    name,
    id,
    nonce,
    active
  };

  //5. 从其它结构体创建实例
  /*let user2 = User {
    name: user1.name
    //...
  };*/
  let user2 = User {
    ..user1
  };
  println!("{}", user2.name); //ahhh

  //6. 元组结构体
  //+ 字段没有名字
  //+ 圆括号
  struct Point(i32,i32);
  let po1 = Point(10, 20);
  let po2 = Point(20, 30);
  println!("{}", po1.0); //10
  println!("{}", po1.1); //20


  //7. 没有任何字段的类单元结构体
  struct A{};
  // 但可以在上面设置成员函数

  //8. 打印结构体
  #[derive(Debug)] //← 添加这个宏后, 再配合 {:?} 在print里进行占位 即可打印结构体实例
  struct User2 {
    name: String,
    id: String,
    nonce: u64,
    active: bool
  }
  let x = User2 {
    name: String::from("ahhh"),
    id: String::from("91209012"),
    nonce: 10000,
    active: true
  };
  println!("user = {:?}", x); //user = User2 { name: "ahhh", id: "91209012", nonce: 10000, active: true }
  println!("user = {:#?}", x); //会自动换行
/*
user = User2 {
    name: "ahhh",
    id: "91209012",
    nonce: 10000,
    active: true,
}
*/
}
